
;(function (global){
	// 用户操作地址
	var CGI = {
		OP_USER_BANK	: window.frontPath + 'user/content/opUserBank'
	};
	
	var ADD_USER_BANK_ERROR = {
			BANK_TYPE 	: {
				NULL : '银行类型不能为空'
			},
			ACCOUNT  	: {
				NULL  : '银行账号不能为空',
				ERROR : '银行账号必须是数字'
			},
			USER_NAME : {
				NULL : '账户姓名不能为空'
			},
			OPENING_NAME: {
				NULL : '开户行不能为空'
			}
		};
		//初始化输入框默认提示组件
		$.placeholder.init();
	
		$.validation.init([{				//银行类型
			ele : $('#user-bank-table [name="bankid"]'),
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				if(_val == ''){
					return ADD_USER_BANK_ERROR.BANK_TYPE.NULL;
				}
				return true;
			}
		},{									//银行账号
			ele : $('#user-bank-table [name="account"]'),
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				if(_val == ''){
					return ADD_USER_BANK_ERROR.ACCOUNT.NULL;
				}
				
				if($.check.isNum(this.ele.val())){
					return true;
				}else{
					return ADD_USER_BANK_ERROR.ACCOUNT.ERROR;
				}
				
				return true;
			}
		},{									//账户姓名
			ele : $('#user-bank-table [name="username"]'),
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				if(_val == ''){
					return ADD_USER_BANK_ERROR.USER_NAME.NULL;
				}
				return true;
			}
		},
		{									//开户行
			ele : $('#user-bank-table [name="openingname"]'),
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				if(_val == ''){
					return ADD_USER_BANK_ERROR.OPENING_NAME.NULL;
				}
				return true;
			}
		}]); 
		
	$('#opUserBank').click(function (){
		if($.validation.isSuccess()){
			$.ajax({ 
			    url: CGI.OP_USER_BANK, 
			    type: 'POST', 
			    dataType: 'json', 
			    data 	: $('#userBankForm').serialize(),
			    contentType: 'application/x-www-form-urlencoded',
			    success: function(data) {
			    	if(0 == data.retcode){
			    		$.alert({
				    		status : 'ok',
							basicTitle : '操作成功！'
						}); 
			    	    return window.setTimeout(function (){
			    			$.none_alert(function (){
			    				window.location.href = window.frontPath+ 'home#/user/banklist';
			    			});
			    		},2000);
			    	}else{
			    		$.alert({
				    		status : 'error',
							basicTitle : data.retmsg
						}); 
			    	}
			    }
			});
		}
	});
})(window);